package org.alanlau.demo;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;

/**
 * test
 *
 * @author liukun
 * @version 1.0
 * @date 2019/12/25 12:49
 */
@Service
public class TestService {
    @Async
    public void test1(int i) {
        System.out.println("执行异步任务: " + i);
    }

    @Async
    public void test2(int i) {
        System.out.println("执行异步任务+1: " + (i + 1));
    }

    @Async
    public ListenableFuture<String> test3(int i) throws InterruptedException {
        Thread.sleep(9000 - i * 1000);
        return new AsyncResult<>("结果:" + i);
    }
}
